<template>
	<view>
		<van-sticky offset-top="0"> 
			<van-tabs :active="active" @change="onChangeTab">
				<van-tab :title="item.name " v-for="(item,index) in tabList" :key="index"></van-tab>
			</van-tabs>
			<van-dropdown-menu>
				<van-dropdown-item v-model="value1" :options="option1" @change='change1' title='类型' />
				<van-dropdown-item v-model="value2" :options="timeColumns" @change='change2' title='时间'  /> 
			</van-dropdown-menu>
		</van-sticky>
        
		<view class="noticeListBox">
			<view v-for="(item,index) in noticeList" :key="index" class="noticeItem" @click="routeTo(item)">
				<view class="title">
					{{ item.smallType.substr(0,1) }}
				</view>
				<view class="content">
					<view class="contentBox">{{ item.title }}</view>
				</view>
				<view v-if="item.isRead=='N'" class="status" style="color:#2daa14">未读 </view>
				<view class="status" style="color:#ff0000" v-else>已读 </view>
			</view>
		</view>
	</view>
</template>
<script setup>  
	import {
		dailyInformationOpenPage
	} from "@/api"
	import {
		onLoad,
		onReachBottom
	} from '@dcloudio/uni-app';
	
	const useDict = useDictStore();
	const INFORMATIION_SMALL_TYPE=useDict.getData("INFORMATIION_SMALL_TYPE"); 
	const INFORMATION_BIG_TYPE=useDict.getData("INFORMATION_BIG_TYPE");  
	const keywords = ref('')
	const active = ref(0)
	import dayjs from 'dayjs'
	const tabList = INFORMATION_BIG_TYPE.map(v=>{
		return{
			name:v.label,
			...v,
		}
	})
	const option1=INFORMATIION_SMALL_TYPE.map(v=>{
		return{
			text:v.label,
			...v,
		}
	})
	const current_time=dayjs().format('YYYY-MM-DD');  
	const changeTime=ref(0)
	
	console.log()
	const timeColumns=ref([
		{ text:'全部', value:0 },
		{ text:'3天内', value:1 },
		{ text:'7天内', value:2 },
		{ text:'近一个月', value:3 }
	])
	const value1=ref('')
	const value2=ref(0)
	const noticeList = ref([])
	const onChangeTab = (e) => { 
		active.value=e
		pageData.value.page=1;
		noticeList.value=[] 
		getlist()
	}
	const change1 =(e)=>{
		pageData.value.page=1;
		noticeList.value=[] 
		getlist()
	}
	const change2 =(e)=>{
		pageData.value.page=1;
		noticeList.value=[] 
		if(e==0){
			changeTime.value=0
		}else if(e==1){
			changeTime.value=dayjs().add(-3, 'day').format('YYYY-MM-DD')
		}else if(e==2){
			changeTime.value=dayjs().add(-7, 'day').format('YYYY-MM-DD')
		}else if(e==3){
			changeTime.value=dayjs().add(-1, 'month').format('YYYY-MM-DD')
		}
		nextTick(()=>{
			getlist()
		})
		
	}
	onLoad(()=>{
		getlist()
	})
	const pageData=ref({
		page:1,
		size:15
	})
	const pages=ref(0)
	
	const getlist = () => { 
		dailyInformationOpenPage({
			current:pageData.value.page,
			size:pageData.value.size,
			createTime_desc:'createTime_desc',
			smallType:value1.value,
			bigType:tabList[active.value].value,
			createTime_le:current_time,
			createTime_ge:changeTime.value
		}).then(res=>{
			pages.value=res.data.pages
			res.data.current==1?noticeList.value=res.data.records:noticeList.value=noticeList.value.concat(res.data.records)
		})
	} 
    onReachBottom(()=>{
		if(pageData.value.page<pages.value){
			pageData.value.page++
			getlist()
		}
	})
	const routeTo = (item) => {
		uni.navigateTo({
			url: '/pages/information/detail/detail?id=' + item.id,
		})
	}
</script>
<style lang="scss" scoped>
	.noticeListBox {
		padding: 20rpx 30rpx;
	}

	.noticeItem {
		display: flex;
		align-items: center;
		padding: 20rpx 30rpx;
		background: #fff;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		font-size: 28rpx;

		.title {
			width: 60rpx;
			height: 60rpx;
			border-radius: 50%;
			text-align: center;
			line-height: 60rpx;
			background: rgb(51, 127, 228);
			margin-right: 20rpx;
			color: #fff;
		}

		.content {
			flex: 1;
			font-size: 28rpx;

			.contentBox {
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				width: 460rpx;
			}
		}
	}
</style>